//package com.mes.eventhandler;
//
//import javax.enterprise.event.Observes;
//
//import org.openbravo.base.model.Entity;
//import org.openbravo.base.model.ModelProvider;
//import org.openbravo.client.kernel.event.EntityDeleteEvent;
//import org.openbravo.client.kernel.event.EntityNewEvent;
//import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
//import org.openbravo.client.kernel.event.EntityUpdateEvent;
//import org.openbravo.dal.service.OBDal;
//
//import com.mes.data.EmesPBom;
//import com.mes.data.EmesPBomItem;
//
//public class EmesPbomEventHandler extends EntityPersistenceEventObserver {
//	private static Entity[] entities = { ModelProvider.getInstance().getEntity(EmesPBom.ENTITY_NAME) };
//
//	@Override
//	protected Entity[] getObservedEntities() {
//		return entities;
//	}
//	public void onUpdate(@Observes EntityUpdateEvent event) throws Throwable {
//		if (!isValidEvent(event)) {
//			return;
//		}
//		//当修改bom的产品时同时修改BomItem的产品
//	    EmesPBom pbom = (EmesPBom) event.getTargetInstance();
//	    String hql = "from " + EmesPBomItem.ENTITY_NAME + " e where " +
//	    		EmesPBomItem.PROPERTY_EmespBOM + " = :pbom and " + EmesPBomItem.PROPERTY_PARENT + " is null";
//	    EmesPBomItem bomItem = (EmesPBomItem)OBDal.getInstance().getSession().createQuery(hql).setEntity("pbom", pbom).uniqueResult();
//	    
//		bomItem.setProduct(pbom.getProduct());
//		bomItem.setUom(pbom.getProduct().getUOM());
//		bomItem.setRevision(pbom.getRevision());
//		
//		OBDal.getInstance().save(bomItem);
//	}
//	
//	//新建头信息时同时保存BomItem
//	public void onSave(@Observes EntityNewEvent event) {
//		if (!isValidEvent(event)) {
//			return;
//		}
//		
//		EmesPBom pbom = (EmesPBom) event.getTargetInstance();
//		
//	}
//	
//	public void onDelete(@Observes
//	EntityDeleteEvent event) {
//		if (!isValidEvent(event)) {
//			return;
//		}
//	}
//}
